package cn.kent.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 演示单条消息过期
 */
@Configuration
public class RabbitConfig {
    public static final String MESSAGE_DELAY_QUEUE_NAME = "message_delay_queue_name";
    public static final String MESSAGE_DELAY_EXCHANGE_NAME = "message_delay_exchange_name";

    @Bean
    Queue messageDelayQueue() {
        return new Queue(MESSAGE_DELAY_QUEUE_NAME, true, false, false);
    }

    @Bean
    DirectExchange directExchange() {
        return new DirectExchange(MESSAGE_DELAY_EXCHANGE_NAME, true, false);
    }

    @Bean
    Binding messageDelayQueueBinding() {
        return BindingBuilder.bind(messageDelayQueue())
                .to(directExchange())
                .with(MESSAGE_DELAY_QUEUE_NAME);
    }
}
